package org.gaaidou.ptarmigan.transactioncoordinator.controller;

import lombok.extern.slf4j.Slf4j;
import org.gaaidou.ptarmigan.transactioncoordinator.bean.Transaction2PC;
import org.gaaidou.ptarmigan.transactioncoordinator.service.Transaction2PCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@Slf4j
public class Transaction2PCController {

    @Autowired
    private Transaction2PCService transaction2PCService;

    @GetMapping(value = "/{txId}")
    @ResponseStatus(HttpStatus.OK)
    public ResponseEntity<Transaction2PC> fetch(@PathVariable("txId") String txId,
                                                @RequestHeader("origin") String origin) {
        return ResponseEntity.ok().body(transaction2PCService.fetch(txId, origin));
    }
}
